/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmTherapy.java
 *
 * Created on Sep 28, 2011, 4:13:33 PM
 */
package khmhappointmentsystem;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.JSpinner;
import javax.swing.JSpinner.DateEditor;
import javax.swing.SpinnerDateModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.text.DateFormatter;
import javax.swing.text.DefaultFormatterFactory;
import org.jdesktop.application.Action;

/**
 *
 * @author mbelisle
 */
public class FrmTherapy extends javax.swing.JInternalFrame {

    static final Logger logger = Logger.getLogger(FrmTherapy.class.getName());
    ArrayList<String> firstName = new ArrayList<String>();
    ArrayList<String> lastName = new ArrayList<String>();
    ArrayList<String> id = new ArrayList<String>();
    ArrayList<String> dob = new ArrayList<String>();
    ArrayList<String> therapist = new ArrayList<String>();
    ArrayList<String> clinic = new ArrayList<String>();
    ArrayList<String> date = new ArrayList<String>();
    ArrayList<String> time = new ArrayList<String>();
    ArrayList<String> checkin = new ArrayList<String>();
    ArrayList<String> sex = new ArrayList<String>();
    ArrayList<String> pull = new ArrayList<String>();
    ArrayList<String> returnDocket = new ArrayList<String>();
    String warnings = "";

    /** Creates new form FrmTherapy */
    public FrmTherapy() {
        initComponents();
        setCalendarDate();
        loadSpecialist();
        loadTherapist();
        loadTherapists();
        populateList();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtSearch = new javax.swing.JTextField();
        cmdSearch = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblSearch = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        txtFirstName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtLastName = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        cmbTherapist = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        txtSSN = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        calClinicDate = new com.toedter.calendar.JDateChooser();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        cmbClinic = new javax.swing.JComboBox();
        cmdAppointment = new javax.swing.JButton();
        Calendar calendar = new GregorianCalendar();
        calendar.set(Calendar.HOUR, 13); // 1pm
        SpinnerDateModel dateModel = new SpinnerDateModel(calendar.getTime(), null,null, Calendar.HOUR);
        spinner = new JSpinner(dateModel);
        jLabel16 = new javax.swing.JLabel();
        chkNewPatient = new javax.swing.JCheckBox();
        jPanel1 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        cmbSpecialist = new javax.swing.JComboBox();
        calDate = new com.toedter.calendar.JDateChooser();
        cmdFind = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblappointments = new javax.swing.JTable();
        jLabel10 = new javax.swing.JLabel();
        txtFtname = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtLtname = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        txtInvoice = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtDiagnosis = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txttreatment = new javax.swing.JTextArea();
        cmdCheckin = new javax.swing.JButton();
        cmbPhysiotherapy = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        txtClinic = new javax.swing.JTextField();
        chkCheck = new javax.swing.JCheckBox();
        jLabel18 = new javax.swing.JLabel();
        txtID = new javax.swing.JTextField();
        cmdCancel = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Physiotherapy Clinic");

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jLabel1.setText("Search Patient:");
        jLabel1.setName("jLabel1"); // NOI18N

        txtSearch.setName("txtSearch"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(FrmTherapy.class, this);
        cmdSearch.setAction(actionMap.get("Search")); // NOI18N
        cmdSearch.setName("cmdSearch"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tblSearch.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblSearch.setName("tblSearch"); // NOI18N
        tblSearch.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblSearchMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblSearch);

        jLabel2.setText("First Name:");
        jLabel2.setName("jLabel2"); // NOI18N

        txtFirstName.setEditable(false);
        txtFirstName.setName("txtFirstName"); // NOI18N

        jLabel3.setText("Last Name:");
        jLabel3.setName("jLabel3"); // NOI18N

        txtLastName.setEditable(false);
        txtLastName.setName("txtLastName"); // NOI18N

        jLabel4.setText("Therapist:");
        jLabel4.setName("jLabel4"); // NOI18N

        cmbTherapist.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbTherapist.setName("cmbTherapist"); // NOI18N

        jLabel5.setText("Patient ID:");
        jLabel5.setName("jLabel5"); // NOI18N

        txtSSN.setEditable(false);
        txtSSN.setName("txtSSN"); // NOI18N

        jLabel6.setText("Checkin Date:");
        jLabel6.setName("jLabel6"); // NOI18N

        calClinicDate.setName("calClinicDate"); // NOI18N

        jLabel7.setText("Checkin Time:");
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText("Specialist Clinic:");
        jLabel8.setName("jLabel8"); // NOI18N

        cmbClinic.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbClinic.setName("cmbClinic"); // NOI18N

        cmdAppointment.setAction(actionMap.get("Appointment")); // NOI18N
        cmdAppointment.setName("cmdAppointment"); // NOI18N

        spinner.setName("spinner"); // NOI18N

        jLabel16.setText("For new Patients please check the box below.");
        jLabel16.setName("jLabel16"); // NOI18N

        chkNewPatient.setText("New Patient");
        chkNewPatient.setName("chkNewPatient"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 517, Short.MAX_VALUE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)
                                .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(36, 36, 36)
                                .addComponent(cmdSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel7)
                                        .addGap(13, 13, 13))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
                                        .addGap(18, 18, 18)))
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(spinner, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                                    .addComponent(txtSSN, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                                    .addComponent(txtFirstName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addGap(24, 24, 24)
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel8)
                                            .addComponent(jLabel4)))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                        .addGap(24, 24, 24)
                                        .addComponent(jLabel3)
                                        .addGap(21, 21, 21)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cmbTherapist, 0, 186, Short.MAX_VALUE)
                                    .addComponent(txtLastName, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE)
                                    .addComponent(cmbClinic, 0, 186, Short.MAX_VALUE))))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(calClinicDate, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(297, 297, 297))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(chkNewPatient)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 283, Short.MAX_VALUE)
                                .addComponent(cmdAppointment, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel16))
                        .addContainerGap())))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmdSearch))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtLastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                    .addComponent(txtSSN)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbTherapist, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(txtFirstName)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                        .addComponent(spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(cmbClinic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(calClinicDate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(chkNewPatient))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(73, 73, 73)
                        .addComponent(cmdAppointment, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)))
                .addContainerGap())
        );

        JFormattedTextField tf = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
        DefaultFormatterFactory factory = (DefaultFormatterFactory) tf.getFormatterFactory();
        DateFormatter formatter = (DateFormatter) factory.getDefaultFormatter();
        spinner.setEditor(new DateEditor(spinner, "hh:mm a"));
        // Change the date format to only show the hours
        formatter.setFormat(new SimpleDateFormat("hh:mm a"));

        jTabbedPane1.addTab("Book Appointment", jPanel2);

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel9.setText("Specialist:");
        jLabel9.setName("jLabel9"); // NOI18N

        cmbSpecialist.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbSpecialist.setName("cmbSpecialist"); // NOI18N

        calDate.setName("calDate"); // NOI18N

        cmdFind.setAction(actionMap.get("Find")); // NOI18N
        cmdFind.setName("cmdFind"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        tblappointments.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblappointments.setName("tblappointments"); // NOI18N
        tblappointments.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblappointmentsMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblappointments);

        jLabel10.setText("First Name:");
        jLabel10.setName("jLabel10"); // NOI18N

        txtFtname.setEditable(false);
        txtFtname.setName("txtFtname"); // NOI18N

        jLabel11.setText("Last Name:");
        jLabel11.setName("jLabel11"); // NOI18N

        txtLtname.setEditable(false);
        txtLtname.setName("txtLtname"); // NOI18N

        jLabel12.setText("Therapist:");
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel13.setText("Invoice #:");
        jLabel13.setName("jLabel13"); // NOI18N

        txtInvoice.setName("txtInvoice"); // NOI18N

        jLabel14.setText("Diagnosis:");
        jLabel14.setName("jLabel14"); // NOI18N

        txtDiagnosis.setName("txtDiagnosis"); // NOI18N

        jLabel15.setText("Treatment:");
        jLabel15.setName("jLabel15"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        txttreatment.setColumns(20);
        txttreatment.setRows(5);
        txttreatment.setName("txttreatment"); // NOI18N
        jScrollPane3.setViewportView(txttreatment);

        cmdCheckin.setAction(actionMap.get("Checkin")); // NOI18N
        cmdCheckin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/khmhappointmentsystem/resources/add.png"))); // NOI18N
        cmdCheckin.setText("Checkin Patients");
        cmdCheckin.setName("cmdCheckin"); // NOI18N

        cmbPhysiotherapy.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbPhysiotherapy.setName("cmbPhysiotherapy"); // NOI18N

        jLabel17.setText("Clinic:");
        jLabel17.setName("jLabel17"); // NOI18N

        txtClinic.setEditable(false);
        txtClinic.setName("txtClinic"); // NOI18N

        chkCheck.setAction(actionMap.get("CheckPatient")); // NOI18N
        chkCheck.setText("Check Patient");
        chkCheck.setName("chkCheck"); // NOI18N

        jLabel18.setText("Patient ID:");
        jLabel18.setName("jLabel18"); // NOI18N

        txtID.setEditable(false);
        txtID.setName("txtID"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbSpecialist, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(calDate, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cmdFind))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                                .addComponent(jLabel10)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(txtFtname, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel11)
                                                    .addComponent(jLabel17))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(txtClinic)
                                                    .addComponent(txtLtname))))
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                                .addComponent(jLabel14)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(txtDiagnosis, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                                .addComponent(jLabel13)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(txtInvoice, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(chkCheck)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 149, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(33, 33, 33))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel12)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(cmbPhysiotherapy, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel15)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmdCheckin)
                                .addGap(26, 26, 26)))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmdFind)
                    .addComponent(calDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel9)
                        .addComponent(cmbSpecialist, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel12)
                        .addComponent(cmbPhysiotherapy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel18)
                        .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(txtFtname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(txtLtname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel17)
                            .addComponent(txtClinic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(txtInvoice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14)
                            .addComponent(txtDiagnosis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(chkCheck)
                            .addComponent(cmdCheckin))))
                .addGap(50, 50, 50))
        );

        jTabbedPane1.addTab("Checkin Patient", jPanel1);

        cmdCancel.setAction(actionMap.get("Cancel")); // NOI18N
        cmdCancel.setName("cmdCancel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 542, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(453, 453, 453)
                        .addComponent(cmdCancel, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 429, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmdCancel, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-572)/2, (screenSize.height-517)/2, 572, 517);
    }// </editor-fold>//GEN-END:initComponents

    private void tblSearchMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblSearchMouseClicked
        // TODO add your handling code here:
        String id_no = tblSearch.getValueAt(tblSearch.getSelectedRow(), 0).toString();
        loadPatientInfo(id_no);
    }//GEN-LAST:event_tblSearchMouseClicked

    private void loadPatientInfo(String selected_id) {
        for (int i = 0; i < id.size(); i++) {
            String pt_id = id.get(i);
            if (selected_id.equals(pt_id)) {
                txtSSN.setText(pt_id);
                txtFirstName.setText(firstName.get(i));
                txtLastName.setText(lastName.get(i));
            }
        }
    }

    private void tblappointmentsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblappointmentsMouseClicked
        // TODO add your handling code here:
        String id_no = tblappointments.getValueAt(tblappointments.getSelectedRow(), 0).toString();
        loadPatient(id_no);
    }//GEN-LAST:event_tblappointmentsMouseClicked

    private void loadPatient(String selected_id) {
        for (int i = 0; i < id.size(); i++) {
            String pt_id = id.get(i);
            if (selected_id.equals(pt_id)) {
                txtID.setText(pt_id);
                txtFtname.setText(firstName.get(i));
                txtLtname.setText(lastName.get(i));
                txtClinic.setText(clinic.get(i));
                //txtTherapist.setText(therapist.get(i));
                cmbPhysiotherapy.setSelectedItem(therapist.get(i));
            }
        }
    }

    void setCalendarDate() {
        calClinicDate.setDate(new java.util.Date());
        calDate.setDate(new java.util.Date());
    }

    private void loadTherapist() {
        cmbTherapist.removeAllItems();
        cmbTherapist.addItem(" ");
        String query = "SELECT DISTINCT therapist FROM therapist";
        try {
            PreparedStatement prep = Environment.getDbConn().prepareStatement(query);
            ResultSet rs = prep.executeQuery();

            while (rs.next()) {
                cmbTherapist.addItem(rs.getString(1));
            }
            rs.close();
            prep.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void loadTherapists() {
        cmbSpecialist.removeAllItems();
        cmbSpecialist.addItem(" ");
        String query = "SELECT DISTINCT therapist FROM therapist";
        try {
            PreparedStatement prep = Environment.getDbConn().prepareStatement(query);
            ResultSet rs = prep.executeQuery();

            while (rs.next()) {
                cmbSpecialist.addItem(rs.getString(1));
            }
            rs.close();
            prep.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void loadSpecialist() {
        cmbClinic.removeAllItems();
        cmbClinic.addItem(" ");
        String query = "SELECT DISTINCT name FROM clinic ORDER BY name";
        try {
            PreparedStatement prep = Environment.getDbConn().prepareStatement(query);
            ResultSet rs = prep.executeQuery();

            while (rs.next()) {
                cmbClinic.addItem(rs.getString(1));
            }
            rs.close();
            prep.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Action
    public void Search() {
        try {

            firstName = new ArrayList<String>();
            lastName = new ArrayList<String>();
            id = new ArrayList<String>();
            dob = new ArrayList<String>();

            String query = "SELECT pt_id, pt_ftname, pt_ltname, pt_DOB FROM Patient_Info WHERE (pt_ftname LIKE ? OR pt_ltname LIKE ?) ORDER BY pt_id, pt_ftname, pt_ltname, pt_DOB";
            PreparedStatement pstmt = Environment.getDbConn().prepareStatement(query);
            pstmt.setString(1, Utilities.percent(txtSearch.getText().trim()));
            pstmt.setString(2, Utilities.percent(txtSearch.getText().trim()));

            ResultSet rs = pstmt.executeQuery();

            while (rs.next()) {
                id.add(rs.getString("pt_id"));
                firstName.add(rs.getString("pt_ftname"));
                lastName.add(rs.getString("pt_ltname"));
                dob.add(Utilities.MDY_Formatter.format(rs.getDate("pt_DOB")));
            }

            if (firstName.isEmpty() == false)//If there were results in the query create a table model with the vectors.
            {
                DefaultTableModel model = new DefaultTableModel() {

                    @Override
                    public Class getColumnClass(int columnIndex) {
                        Object o = getValueAt(0, columnIndex);
                        if (o == null) {
                            return Object.class;
                        } else {
                            return o.getClass();
                        }
                    }
                };

                model.addColumn("ID", id.toArray());
                model.addColumn("First Name", firstName.toArray());
                model.addColumn("Last Name", lastName.toArray());
                model.addColumn("Date of Birth", dob.toArray());
                tblSearch.setModel(model);
            } else //If the query returned no results create a table model that displays a "No Result" message and disables the view salaries register button.
            {
                DefaultTableModel model = new DefaultTableModel() {

                    @Override
                    public boolean isCellEditable(int row, int column) {
                        return false;
                    }

                    @Override
                    public Class getColumnClass(int columnIndex) {
                        Object o = getValueAt(0, columnIndex);
                        if (o == null) {
                            return Object.class;
                        } else {
                            return o.getClass();
                        }
                    }
                };

                id.add("No Results");
                firstName.add("No Results");
                lastName.add("No Results");
                dob.add("No Results");

                model.addColumn("ID", id.toArray());
                model.addColumn("First Name", firstName.toArray());
                model.addColumn("Last Name", lastName.toArray());
                model.addColumn("Date of Birth", dob.toArray());
                tblSearch.setModel(model);
            }
        } catch (Exception e) {
            String message = "An error occurred while searching for the patients.";
            logger.log(Level.SEVERE, message, e);
        }
    }

    @Action
    public void Appointment() {
         if (!passedValidation())
        {
            Utilities.showWarningMessage(rootPane, warnings);
            return;
        }
        //create object for date
        DateFormat MDY_Formatter = new SimpleDateFormat("MM-dd-yyyy");
        DateFormat Time_Formatter = new SimpleDateFormat("hh:mm a");
        String ptdate = MDY_Formatter.format(calClinicDate.getDate());
        String pt_id = txtSSN.getText();
        String ptclinic = cmbClinic.getSelectedItem().toString();
        String specialist = cmbTherapist.getSelectedItem().toString();
        String pttime = Time_Formatter.format(spinner.getValue());
        String check = "y";
        String message = "";

          if (chkNewPatient.isSelected()) {
        try {
            String query = "INSERT INTO Appointments ("
                    + "pt_id,"
                    + "clinic,"
                    + "specialist,"
                    + "date,"
                    + "time,"
                    + "new_patient)"
                    + "Values(?,?,?,?,?,?)";

            PreparedStatement stmt = Environment.getDbConn().prepareStatement(query);
            stmt.setString(1, pt_id);
            stmt.setString(2, ptclinic);
            stmt.setString(3, specialist);
            stmt.setString(4, ptdate);
            stmt.setString(5, pttime);
            stmt.setString(6, check);

            stmt.executeUpdate();
            JOptionPane.showMessageDialog(rootPane, "New Appointment booked successfully.");
            chkNewPatient.setSelected(false);
        } catch (Exception e) {
            System.out.println("Error occured while booking patient appointment.");
            e.printStackTrace();
        }
         } else {
            try {
                String query = "INSERT INTO Appointments ("
                        + "pt_id,"
                        + "clinic,"
                        + "specialist,"
                        + "date,"
                        + "time)"
                        + "Values(?,?,?,?,?)";

                PreparedStatement stmt = Environment.getDbConn().prepareStatement(query);
                stmt.setString(1, pt_id);
                stmt.setString(2, ptclinic);
                stmt.setString(3, specialist);
                stmt.setString(4, ptdate);
                stmt.setString(5, pttime);

                stmt.executeUpdate();
                JOptionPane.showMessageDialog(rootPane, "New Appointment booked successfully.");
            } catch (Exception e) {
                Utilities.showErrorMessage(rootPane, message);
                message = "Error occured while booking patient appointment.";
                e.printStackTrace();
            }
        }

        txtSSN.setText("");
        txtFirstName.setText("");
        txtLastName.setText("");
    }

    @Action
    public void Cancel() {
        this.dispose();
    }
    
    private void populateList(){
        cmbPhysiotherapy.setModel(new DefaultComboBoxModel(Clinic.getUser().toArray()) );
    }

    @Action
    public void Find() {
        //create object for date
        DateFormat MDY_Formatter = new SimpleDateFormat("MM-dd-yyyy");
        String newDate = MDY_Formatter.format(calDate.getDate());

        try {

            firstName = new ArrayList<String>();
            lastName = new ArrayList<String>();
            id = new ArrayList<String>();
            clinic = new ArrayList<String>();
            therapist = new ArrayList<String>();
            date = new ArrayList<String>();
            time = new ArrayList<String>();
            checkin = new ArrayList<String>();
            sex = new ArrayList<String>();
            pull = new ArrayList<String>();
            returnDocket = new ArrayList<String>();


            String query = "SELECT Patient_Info.pt_id, Patient_Info.pt_ftname, Patient_Info.pt_ltname, Appointments.clinic, Appointments.specialist,"
                    + "Appointments.date, Appointments.time, Appointments.checkin, Appointments.docket_pull, Appointments.docket_return, Patient_Info.pt_sex "
                    + " FROM Appointments INNER Join Patient_Info ON "
                    + " Patient_Info.pt_id = Appointments.pt_id "
                    + "WHERE Appointments.specialist LIKE ? AND Appointments.date LIKE ? Group By Patient_Info.pt_id, Appointments.specialist, Appointments.clinic,Appointments.date, Appointments.docket_pull, Appointments.docket_return, Appointments.time,"
                    + "Patient_Info.pt_ftname, Patient_Info.pt_ltname, Patient_Info.pt_sex, Appointments.checkin "
                    + "Order by Appointments.specialist";
            PreparedStatement pstmt = Environment.getDbConn().prepareStatement(query);
            pstmt.setString(1, cmbSpecialist.getSelectedItem().toString());
            pstmt.setString(2, newDate);

            ResultSet rs = pstmt.executeQuery();

            while (rs.next()) {
                id.add(rs.getString("pt_id"));
                firstName.add(rs.getString("pt_ftname"));
                lastName.add(rs.getString("pt_ltname"));
                clinic.add(rs.getString("clinic"));
                therapist.add(rs.getString("specialist"));
                date.add(rs.getString("date"));
                time.add(rs.getString("time"));
                checkin.add(rs.getString("Checkin"));
                pull.add(rs.getString("docket_pull"));
                returnDocket.add(rs.getString("docket_return"));

            }


            if (firstName.isEmpty() == false)//If there were results in the query create a table model with the vectors.
            {
                DefaultTableModel model = new DefaultTableModel() {

                    @Override
                    public Class getColumnClass(int columnIndex) {
                        Object o = getValueAt(0, columnIndex);
                        if (o == null) {
                            return Object.class;
                        } else {
                            return o.getClass();
                        }
                    }
                };

                model.addColumn("ID", id.toArray());
                model.addColumn("First Name", firstName.toArray());
                model.addColumn("Last Name", lastName.toArray());
                model.addColumn("Clinic", clinic.toArray());
                model.addColumn("Specialist", therapist.toArray());
                model.addColumn("Date", date.toArray());
                model.addColumn("Time", time.toArray());
                model.addColumn("Checkin", checkin.toArray());
                model.addColumn("Pull", pull.toArray());
                model.addColumn("Return", returnDocket.toArray());
                tblappointments.setModel(model);

            } else //If the query returned no results create a table model that displays a "No Result" message and disables the view salaries register button.
            {
                DefaultTableModel model = new DefaultTableModel() {

                    @Override
                    public boolean isCellEditable(int row, int column) {
                        return false;
                    }

                    @Override
                    public Class getColumnClass(int columnIndex) {
                        Object o = getValueAt(0, columnIndex);
                        if (o == null) {
                            return Object.class;
                        } else {
                            return o.getClass();
                        }
                    }
                };

                id.add("No Results");
                firstName.add("No Results");
                lastName.add("No Results");
                clinic.add("No Results");
                therapist.add("No Results");
                date.add("No Results");
                time.add("No Results");
                checkin.add("No Results");
                pull.add("No Results");
                returnDocket.add("No Results");
                JOptionPane.showMessageDialog(rootPane, "No Appiontments exist for this specialist clinic.");

                model.addColumn("ID", id.toArray());
                model.addColumn("First Name", firstName.toArray());
                model.addColumn("Last Name", lastName.toArray());
                model.addColumn("Clinic", clinic.toArray());
                model.addColumn("Specialist", therapist.toArray());
                model.addColumn("Date", date.toArray());
                model.addColumn("Time", time.toArray());
                model.addColumn("Checkin", checkin.toArray());
                model.addColumn("Pull", pull.toArray());
                model.addColumn("Return", returnDocket.toArray());
                tblappointments.setModel(model);

            }
        } catch (Exception e) {
            String message = "An error occurred while searching for the patients.";
            logger.log(Level.SEVERE, message, e);
        }
    }

    @Action
    public void Checkin() {
        
       
        DateFormat MDY_Formatter = new SimpleDateFormat("MM-dd-yyyy");
        String clinicdate = MDY_Formatter.format(calDate.getDate());
        String idnumber = txtID.getText().toString();
        String ptclinic = txtClinic.getText().toString();
        String fname = txtFtname.getText().toString();
        String lname = txtLtname.getText().toString();
        String treatment = txttreatment.getText().toString();
        String invoice = txtInvoice.getText().toString();
        String diagnosis = txtDiagnosis.getText().toString();
        String name = cmbPhysiotherapy.getSelectedItem().toString();
        boolean checkinPatient = Clinic.CheckinAppointments(idnumber, ptclinic, name, invoice, diagnosis, treatment, clinicdate);
         if (checkinPatient)
        {
            String message = "The patient was successfully checkedin.\n"
                             + "Would you like to add another?";
            int response = Utilities.showConfirmDialog(rootPane, message);
            if (response == JOptionPane.YES_OPTION)
            {
                resetForm();
            }
            else
            {
                resetForm();
            }
        }
        else // If it doesn't get added tell the user something went wrong.
        {
            String message = "An error occurred while checking in the patient.\n"
                             + "Kindly verify your information and try again.\n"
                             + "If the problem persists, kindly contact your system administrator.";
            Utilities.showErrorMessage(rootPane, message);
        }

    }
    
    private void resetForm()
    {
        txtID.setText("");
        txtFtname.setText("");
        txtLtname.setText("");
        txtClinic.setText("");
        txtInvoice.setText("");
        txtDiagnosis.setText("");
        txttreatment.setText("");
        populateList();
    }

    /**
     * Creates a flag in the appointments table to indicate that the patient was checked in for the clinic.
     */
    @Action
    public void CheckPatient() {
        String check = "y";
        DateFormat MDY_Formatter = new SimpleDateFormat("MM-dd-yyyy");
        String clinicdate = MDY_Formatter.format(calDate.getDate());
        String idnumber = txtID.getText().toString();
        String ptclinic = txtClinic.getText().toString();

        //if the patient showed up for appointment place a flag in the database to indiciate
        if (chkCheck.isSelected()) {
            try {
                String query = "Update Appointments Set checkin = '" + check + "', checkin_date = '" + clinicdate + "' Where pt_id LIKE '" + idnumber + "'AND clinic LIKE '" + ptclinic + "'";
                PreparedStatement pstmt = Environment.getDbConn().prepareStatement(query);

                pstmt.executeUpdate();
            } catch (Exception e) {
                String message = "An error occurred while checking in patient.";
                logger.log(Level.SEVERE, message, e);
            }
        }
        JOptionPane.showMessageDialog(rootPane, "Successful.");
    }
    
    private boolean passedValidation(){
        boolean passed = true;
        warnings = "";
        String ptid = txtSSN.getText().trim();
        String fname = txtFirstName.getText().trim();
        String lname = txtLastName.getText().trim();
        String ptclinic = cmbClinic.getSelectedItem().toString();
        
        
        if (ptid.isEmpty()){
             warnings += "Pateint ID cannot be empty.\n";
            passed = false;
        }
        if (fname.isEmpty()){
             warnings += "First Name cannot be empty.\n";
            passed = false;
        }
        if (lname.isEmpty()){
             warnings += "Last Name cannot be empty.\n";
            passed = false;
        }
        
        return passed;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.toedter.calendar.JDateChooser calClinicDate;
    private com.toedter.calendar.JDateChooser calDate;
    private javax.swing.JCheckBox chkCheck;
    private javax.swing.JCheckBox chkNewPatient;
    private javax.swing.JComboBox cmbClinic;
    private javax.swing.JComboBox cmbPhysiotherapy;
    private javax.swing.JComboBox cmbSpecialist;
    private javax.swing.JComboBox cmbTherapist;
    private javax.swing.JButton cmdAppointment;
    private javax.swing.JButton cmdCancel;
    private javax.swing.JButton cmdCheckin;
    private javax.swing.JButton cmdFind;
    private javax.swing.JButton cmdSearch;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JSpinner spinner;
    private javax.swing.JTable tblSearch;
    private javax.swing.JTable tblappointments;
    private javax.swing.JTextField txtClinic;
    private javax.swing.JTextField txtDiagnosis;
    private javax.swing.JTextField txtFirstName;
    private javax.swing.JTextField txtFtname;
    private javax.swing.JTextField txtID;
    private javax.swing.JTextField txtInvoice;
    private javax.swing.JTextField txtLastName;
    private javax.swing.JTextField txtLtname;
    private javax.swing.JTextField txtSSN;
    private javax.swing.JTextField txtSearch;
    private javax.swing.JTextArea txttreatment;
    // End of variables declaration//GEN-END:variables
}
